import QtQuick 2.0
import QtQuick.Window 2.2

Item {
    id: node
    width: rect.width
    height: rect.height

    property real moveXTime: 0
    property real moveYTime: 0

    function move(sx, sy, tx, ty)
    {
        bx.enabled = false
        by.enabled = false
        node.x = sx
        node.y = sy

        console.log(node.x, node.y, tx, ty)
        moveXTime = Math.abs(tx - node.x) / Screen.width * 20000
        moveYTime = Math.abs(ty - node.y) / Screen.height * 20000

        bx.enabled = true
        by.enabled = true
        node.x = tx
        node.y = ty
    }

    Rectangle{
        id: rect
        width: 5
        height: width
        radius: 50
    }

    Behavior on x {
        id: bx
        NumberAnimation{ duration: moveXTime; }
    }

    Behavior on y {
        id: by
        NumberAnimation{ duration: moveYTime; }
    }

    Timer{
        interval: 500
        repeat: true
        running: true
        onTriggered: {
            // 超过边界
            if(node.x < -100)
            {
                _NODES_POOL.push(node)
            }
            else if(node.x > Screen.width+100)
            {
                _NODES_POOL.push(node)
            }
            else if(node.y < -100)
            {
                _NODES_POOL.push(node)
            }
            else if(node.y > Screen.height+100)
            {
                _NODES_POOL.push(node)
            }
        }
    }
}
